﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace _180FrameWork.Common
{
  public   class WindowsMessageHelper
    {
        [DllImport("User32.dll", EntryPoint = "SendMessage")]
        public static extern int SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, ref COPYDATASTRUCT lParam);

        public const UInt32 WM_COPYDATA = 0x004A;

        public static  int sendWindowsStringMessage(IntPtr hWnd, string msg)
        {
            int result = 0;
            COPYDATASTRUCT cds = new COPYDATASTRUCT();
            cds.lpData = msg;
            cds.cbData = Encoding.Unicode.GetBytes(msg).Length;
            result = SendMessage(hWnd, WM_COPYDATA, IntPtr.Zero, ref cds);
            return result;
        }
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct COPYDATASTRUCT
    {
        public int dwData;
        public int cbData;
        [MarshalAs(UnmanagedType.LPStr)]
        public string lpData;
    }
}
